package com.yu.rpc.core.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class MockServiceProxy implements InvocationHandler {

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Class<?> methodReturnType = method.getReturnType();
        return getDefaultObject(methodReturnType);
    }

    private Object getDefaultObject(Class<?> type) {
        if (type.isPrimitive()) {
            if (type.equals(boolean.class)) {
                return false;
            } else if (type.equals(int.class)) {
                return 0;
            } else if (type.equals(long.class)) {
                return 0L;
            } else if (type.equals(float.class)) {
                return 0.0f;
            } else if (type.equals(double.class)) {
                return 0.0d;
            } else if (type.equals(String.class)) {
                return "";
            } else if (type.equals(short.class)) {
                return (short) 0;
            }
        }
        return null;
    }
}
